package dao;

import model.House;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;

public class HouseDao {
    public int add(Connection con, House house) throws Exception{
        String sql="insert into t_house (null,?)";
        PreparedStatement pstmt=con.prepareStatement(sql);
        pstmt.setString(1,house.getHouseName());
        return pstmt.executeUpdate();
    }
    public int update(Connection con,House house) throws Exception{
        String sql="update t_house set houseName=? where id=?";
        PreparedStatement pstmt=con.prepareStatement(sql);
        pstmt.setString(1,house.getHouseName());
        pstmt.setInt(2,house.getId());
        return pstmt.executeUpdate();
    }
    public int delete(Connection con,String id) throws Exception{
        String sql="delete from t_house where id=?";
        PreparedStatement pstmt=con.prepareStatement(sql);
        pstmt.setString(1,id);
        return pstmt.executeUpdate();
    }
}
